﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VectorEditor
{
	public class EditorController
	{
		private Document document;
		private Stack<Command> commandStack = new Stack<Command>();
        private Stack<Command> undoStack = new Stack<Command>();

        public bool CanUndo { get { return commandStack.Count > 0; } }
        public bool CanRedo { get { return undoStack.Count > 0; } }

		public EditorController(Document doc)
		{
			document = doc;
		}
		public void PushCommand(Command cmd)
		{
            commandStack.Push(cmd);
            cmd.Execute(document);
            undoStack.Clear();
        }
		public void Undo()
		{
            if (CanUndo)
            {
                Command cmd = commandStack.Pop();
                undoStack.Push(cmd);
                cmd.Undo(document);
            }
        }
		public void Redo()
		{
            if (CanRedo)
            {
                Command cmd = undoStack.Pop();
                commandStack.Push(cmd);
                cmd.Execute(document);
            }
        }
	}
}
